<?php
/**
 * BootstrapIE6 class file.
 * @author hightman
 */
Yii::import('application.vendors.YiiBooster.src.components.Bootstrap', true);

/**
 * BootstrapIE6 application component.
 */
class EBootstrapIE6 extends Bootstrap
{
	public $bsie = 'application.vendors.bsie';
	public $html5shiv = 'http://html5shiv.googlecode.com/svn/trunk/html5.js';
	protected $_ie6AssetsUrl;

	/**
	 * Add bsie files
	 */
	public function init()
	{
		parent::init();
		// css patch
		$cs = Yii::app()->clientScript;
		$cs->registerCssFile($this->getIe6AssetsUrl() . '/css/bootstrap-ie6' . (!YII_DEBUG ? '.min' : '') . '.css', 'lte IE 6');
		$cs->registerCssFile($this->getIe6AssetsUrl() . '/css/ie.css', 'lte IE 6');
		// js patch
		$url = Yii::app()->assetManager->publish(Yii::getPathOfAlias($this->bsie . '.js') . '/bootstrap-ie.js');
		$cs->registerScriptFile($url, $cs->coreScriptPosition, array('media' => 'lte IE 6'));
		if ($this->html5shiv) {
			$cs->registerScriptFile($this->html5shiv, CClientScript::POS_HEAD, array('media' => 'lt IE 9'));
		}
	}

	/**
	 * Returns the URL to the published assets folder of IE6 patch.
	 * @return string the URL
	 */
	protected function getIe6AssetsUrl()
	{
		if ($this->_ie6AssetsUrl === null) {
			$url = Yii::app()->assetManager->publish(Yii::getPathOfAlias($this->bsie . '.bootstrap'));
			$this->_ie6AssetsUrl = $url;
		}
		return $this->_ie6AssetsUrl;
	}

	/**
	 * Returns the extension version number.
	 * @return string the version
	 */
	public function getVersion()
	{
		$version = parent::getVersion();
		if ($this->bsie) {
			$version .= '_bsie';
		}
		return $version;
	}
}
